{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Entry Orders"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This section covers **entry orders**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import fxcmpy\n",
    "import pandas as pd\n",
    "import datetime as dt\n",
    "con = fxcmpy.fxcmpy(config_file='fxcm.cfg')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Existing Orders"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After connecting the FXCM Server, `fxcm.py` collects all existing orders. `list` or `DataFrame` object of the existing orders is returned by the `con.get_orders()` method."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>accountId</th>\n",
       "      <td>2815291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>accountName</th>\n",
       "      <td>02815291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>amountK</th>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>buy</th>\n",
       "      <td>1.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency</th>\n",
       "      <td>EUR/USD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currencyPoint</th>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>expireDate</th>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isBuy</th>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isELSOrder</th>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isEntryOrder</th>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isLimitOrder</th>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isNetQuantity</th>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isStopOrder</th>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>limit</th>\n",
       "      <td>1.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>limitPegBaseType</th>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>limitRate</th>\n",
       "      <td>1.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ocoBulkId</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>orderId</th>\n",
       "      <td>96257004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>range</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ratePrecision</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sell</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>status</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stop</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stopMove</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stopPegBaseType</th>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stopRate</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>t</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <td>01112018103438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>timeInForce</th>\n",
       "      <td>GTC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>tradeId</th>\n",
       "      <td>96257005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>type</th>\n",
       "      <td>LE</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               0\n",
       "accountId                2815291\n",
       "accountName             02815291\n",
       "amountK                      100\n",
       "buy                         1.18\n",
       "currency                 EUR/USD\n",
       "currencyPoint                 10\n",
       "expireDate                      \n",
       "isBuy                       True\n",
       "isELSOrder                 False\n",
       "isEntryOrder                True\n",
       "isLimitOrder                True\n",
       "isNetQuantity              False\n",
       "isStopOrder                False\n",
       "limit                        1.2\n",
       "limitPegBaseType              -1\n",
       "limitRate                    1.2\n",
       "ocoBulkId                      0\n",
       "orderId                 96257004\n",
       "range                          0\n",
       "ratePrecision                  5\n",
       "sell                           0\n",
       "status                         1\n",
       "stop                           0\n",
       "stopMove                       0\n",
       "stopPegBaseType               -1\n",
       "stopRate                       0\n",
       "t                              3\n",
       "time              01112018103438\n",
       "timeInForce                  GTC\n",
       "tradeId                 96257005\n",
       "type                          LE"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "con.get_orders().T  # returns DataFrame by default"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'accountId': '2815291',\n",
       "  'accountName': '02815291',\n",
       "  'amountK': 100,\n",
       "  'buy': 1.18,\n",
       "  'currency': 'EUR/USD',\n",
       "  'currencyPoint': 10,\n",
       "  'expireDate': '',\n",
       "  'isBuy': True,\n",
       "  'isELSOrder': False,\n",
       "  'isEntryOrder': True,\n",
       "  'isLimitOrder': True,\n",
       "  'isNetQuantity': False,\n",
       "  'isStopOrder': False,\n",
       "  'limit': 1.2,\n",
       "  'limitPegBaseType': -1,\n",
       "  'limitRate': 1.2,\n",
       "  'ocoBulkId': 0,\n",
       "  'orderId': '96257004',\n",
       "  'range': 0,\n",
       "  'ratePrecision': 5,\n",
       "  'sell': 0,\n",
       "  'status': 1,\n",
       "  'stop': 0,\n",
       "  'stopMove': 0,\n",
       "  'stopPegBaseType': -1,\n",
       "  'stopRate': 0,\n",
       "  't': 3,\n",
       "  'time': '01112018103438',\n",
       "  'timeInForce': 'GTC',\n",
       "  'tradeId': '96257005',\n",
       "  'type': 'LE'}]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "con.get_orders(kind='list')  #  returns a list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Each order has a unique `order_id`, these `ids` are returned by `con.get_order_ids()`. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[96257004]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "con.get_order_ids()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Placing Entry Orders"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Entry orders are placed via the `con.create_entry_order()` method. For a detailed description of the parameters refer to the <a href=\"https://fxcmapi.github.io/rest-api-docs/#operation/createEntryOrder\">FXCM API documentation</a>."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "order = con.create_entry_order(symbol='USD/JPY', is_buy=True, \n",
    "                               amount=300, limit=112, \n",
    "                               is_in_pips = False,\n",
    "                               time_in_force='GTC', rate=110, \n",
    "                               stop=None, trailing_step=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>accountId</th>\n",
       "      <td>2815291</td>\n",
       "      <td>2815291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>accountName</th>\n",
       "      <td>02815291</td>\n",
       "      <td>02815291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>amountK</th>\n",
       "      <td>100</td>\n",
       "      <td>300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>buy</th>\n",
       "      <td>1.18</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency</th>\n",
       "      <td>EUR/USD</td>\n",
       "      <td>USD/JPY</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currencyPoint</th>\n",
       "      <td>10</td>\n",
       "      <td>26.8773</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>expireDate</th>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isBuy</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isELSOrder</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isEntryOrder</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isLimitOrder</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isNetQuantity</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isStopOrder</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>limit</th>\n",
       "      <td>1.2</td>\n",
       "      <td>112</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>limitPegBaseType</th>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>limitRate</th>\n",
       "      <td>1.2</td>\n",
       "      <td>112</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ocoBulkId</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>orderId</th>\n",
       "      <td>96257004</td>\n",
       "      <td>96266380</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>range</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ratePrecision</th>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sell</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>status</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stop</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stopMove</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stopPegBaseType</th>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stopRate</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>t</th>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <td>01112018103438</td>\n",
       "      <td>01112018121455984</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>timeInForce</th>\n",
       "      <td>GTC</td>\n",
       "      <td>GTC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>tradeId</th>\n",
       "      <td>96257005</td>\n",
       "      <td>96266381</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>type</th>\n",
       "      <td>LE</td>\n",
       "      <td>LE</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               0                  1\n",
       "accountId                2815291            2815291\n",
       "accountName             02815291           02815291\n",
       "amountK                      100                300\n",
       "buy                         1.18                110\n",
       "currency                 EUR/USD            USD/JPY\n",
       "currencyPoint                 10            26.8773\n",
       "expireDate                                         \n",
       "isBuy                       True               True\n",
       "isELSOrder                 False              False\n",
       "isEntryOrder                True               True\n",
       "isLimitOrder                True               True\n",
       "isNetQuantity              False              False\n",
       "isStopOrder                False              False\n",
       "limit                        1.2                112\n",
       "limitPegBaseType              -1                 -1\n",
       "limitRate                    1.2                112\n",
       "ocoBulkId                      0                  0\n",
       "orderId                 96257004           96266380\n",
       "range                          0                  0\n",
       "ratePrecision                  5                  3\n",
       "sell                           0                  0\n",
       "status                         1                  1\n",
       "stop                           0                  0\n",
       "stopMove                       0                  0\n",
       "stopPegBaseType               -1                 -1\n",
       "stopRate                       0                  0\n",
       "t                              3                  3\n",
       "time              01112018103438  01112018121455984\n",
       "timeInForce                  GTC                GTC\n",
       "tradeId                 96257005           96266381\n",
       "type                          LE                 LE"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "con.get_orders().T"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Changing Orders "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are two methods to change entry orders:\n",
    "    \n",
    "* `change_order_stop_limit()` to change an order's stop or limit rate.\n",
    "* `change_order()` to change an order's amount, rate, order range and/or trailing step."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "order_id = con.get_order_ids()[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "96266380"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "order_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "con.change_order_stop_limit(order_id=order_id, is_stop_in_pips=True, \n",
    "                            is_limit_in_pips=True, limit=110, stop=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "con.change_order(order_id=order_id, amount=500, rate=100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The order is changed accordingly."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>accountId</th>\n",
       "      <td>2815291</td>\n",
       "      <td>2815291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>accountName</th>\n",
       "      <td>02815291</td>\n",
       "      <td>02815291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>amountK</th>\n",
       "      <td>100</td>\n",
       "      <td>500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>buy</th>\n",
       "      <td>1.18</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency</th>\n",
       "      <td>EUR/USD</td>\n",
       "      <td>USD/JPY</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currencyPoint</th>\n",
       "      <td>10</td>\n",
       "      <td>44.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>expireDate</th>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isBuy</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isELSOrder</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isEntryOrder</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isLimitOrder</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isNetQuantity</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isStopOrder</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>limit</th>\n",
       "      <td>1.2</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>limitPegBaseType</th>\n",
       "      <td>-1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>limitRate</th>\n",
       "      <td>1.2</td>\n",
       "      <td>101.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ocoBulkId</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>orderId</th>\n",
       "      <td>96257004</td>\n",
       "      <td>96266380</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>range</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ratePrecision</th>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sell</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>status</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stop</th>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stopMove</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stopPegBaseType</th>\n",
       "      <td>-1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stopRate</th>\n",
       "      <td>0</td>\n",
       "      <td>99.968</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>t</th>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <td>01112018103438</td>\n",
       "      <td>01112018121511947</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>timeInForce</th>\n",
       "      <td>GTC</td>\n",
       "      <td>GTC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>tradeId</th>\n",
       "      <td>96257005</td>\n",
       "      <td>96266381</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>type</th>\n",
       "      <td>LE</td>\n",
       "      <td>LE</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               0                  1\n",
       "accountId                2815291            2815291\n",
       "accountName             02815291           02815291\n",
       "amountK                      100                500\n",
       "buy                         1.18                100\n",
       "currency                 EUR/USD            USD/JPY\n",
       "currencyPoint                 10              44.79\n",
       "expireDate                                         \n",
       "isBuy                       True               True\n",
       "isELSOrder                 False              False\n",
       "isEntryOrder                True               True\n",
       "isLimitOrder                True               True\n",
       "isNetQuantity              False              False\n",
       "isStopOrder                False              False\n",
       "limit                        1.2                110\n",
       "limitPegBaseType              -1                  0\n",
       "limitRate                    1.2              101.1\n",
       "ocoBulkId                      0                  0\n",
       "orderId                 96257004           96266380\n",
       "range                          0                  0\n",
       "ratePrecision                  5                  3\n",
       "sell                           0                  0\n",
       "status                         1                  1\n",
       "stop                           0                 -1\n",
       "stopMove                       0                  0\n",
       "stopPegBaseType               -1                  1\n",
       "stopRate                       0             99.968\n",
       "t                              3                  3\n",
       "time              01112018103438  01112018121511947\n",
       "timeInForce                  GTC                GTC\n",
       "tradeId                 96257005           96266381\n",
       "type                          LE                 LE"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "con.get_orders().T"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Deleting Orders"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Orders can be **deleted** through the method `con.delete_orders()`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[96257004, 96266380]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "con.get_order_ids()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "con.delete_order(order_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>accountId</th>\n",
       "      <td>2815291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>accountName</th>\n",
       "      <td>02815291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>amountK</th>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>buy</th>\n",
       "      <td>1.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency</th>\n",
       "      <td>EUR/USD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currencyPoint</th>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>expireDate</th>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isBuy</th>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isELSOrder</th>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isEntryOrder</th>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isLimitOrder</th>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isNetQuantity</th>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>isStopOrder</th>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>limit</th>\n",
       "      <td>1.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>limitPegBaseType</th>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>limitRate</th>\n",
       "      <td>1.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ocoBulkId</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>orderId</th>\n",
       "      <td>96257004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>range</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ratePrecision</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sell</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>status</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stop</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stopMove</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stopPegBaseType</th>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stopRate</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>t</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <td>01112018103438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>timeInForce</th>\n",
       "      <td>GTC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>tradeId</th>\n",
       "      <td>96257005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>type</th>\n",
       "      <td>LE</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               0\n",
       "accountId                2815291\n",
       "accountName             02815291\n",
       "amountK                      100\n",
       "buy                         1.18\n",
       "currency                 EUR/USD\n",
       "currencyPoint                 10\n",
       "expireDate                      \n",
       "isBuy                       True\n",
       "isELSOrder                 False\n",
       "isEntryOrder                True\n",
       "isLimitOrder                True\n",
       "isNetQuantity              False\n",
       "isStopOrder                False\n",
       "limit                        1.2\n",
       "limitPegBaseType              -1\n",
       "limitRate                    1.2\n",
       "ocoBulkId                      0\n",
       "orderId                 96257004\n",
       "range                          0\n",
       "ratePrecision                  5\n",
       "sell                           0\n",
       "status                         1\n",
       "stop                           0\n",
       "stopMove                       0\n",
       "stopPegBaseType               -1\n",
       "stopRate                       0\n",
       "t                              3\n",
       "time              01112018103438\n",
       "timeInForce                  GTC\n",
       "tradeId                 96257005\n",
       "type                          LE"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "con.get_orders().T"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Deleted or executed orders of the current session are stored in the attribute `old_orders` as an `fxcm_order` object."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{96266380: <fxcm.fxcm_order at 0x7f5d481ceb70>}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "con.old_orders"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
